﻿<%@ Page Language="C#" MasterPageFile="~/Manager.master" AutoEventWireup="true" CodeFile="AddCatalogue.aspx.cs"
    Inherits="Manager_Catalogue_AddCatalogue" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div align="center">
        <table id="tblBodyMain" style="width: 90%" border="1" cellpadding="2" cellspacing="2"
            class="tbl_Comon-Search">
            <tr>
                <td align="left" class="td_Control" colspan="2">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="grpAdd" />
                </td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 158px">
                    Thể loại</td>
                <td align="left" class="td_Control">
                    <asp:TextBox ID="txtTheLoai" runat="server" Width="92%" ValidationGroup="grpAdd"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTheLoai"
                        ErrorMessage="Nhập thể loại" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 158px">
                    Chủ đề</td>
                <td align="left" class="td_Control">
                    <asp:DropDownList ID="ddlChuDe" runat="server" ValidationGroup="grpAdd">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlChuDe"
                        ErrorMessage="Chọn chủ đề" InitialValue="0" ValidationGroup="grpAdd">*</asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td class="td_Title" style="width: 158px">
                    Loại</td>
                <td align="left" class="td_Control">
                    <asp:DropDownList ID="ddlKindNo" runat="server" CssClass="cssDropdownlist" ForeColor="#0000C0">
                    </asp:DropDownList></td>
            </tr>
            <tr id="trCatProp" runat="server">
                <td class="td_Title" style="width: 158px">
                    Copy thuộc tính thể loại</td>
                <td align="left" class="td_Control">
                    <asp:DropDownList ID="ddlCatProp" runat="server" ValidationGroup="grpAdd" AutoPostBack="True"
                        OnSelectedIndexChanged="ddlCatProp_SelectedIndexChanged">
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td class="td_Title" nowrap="nowrap" style="width: 158px">
                    Cho xem</td>
                <td align="left" class="td_Control">
                    <asp:CheckBox ID="chk_state" runat="server" Checked="True" /></td>
            </tr>
            <tr>
                <td align="left" class="td_Control" colspan="2">
                    <asp:GridView ID="grv_Catalogue" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        BorderColor="#407DB3" CellPadding="2" Width="100%" OnRowDeleting="grv_Catalogue_RowDeleting" DataKeyNames="PrtID"> 
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Danh sách các thuộc tính
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="txtThuocTinh" runat="server" onkeyup="tblInsertRow(this)" Text='<%# Eval("PrtNm") %>'
                                        Width="99%"></asp:TextBox>
                                    <asp:Label ID="lblPrtID" runat="server" Text='<%# Eval("PrtID") %>' Style="display: none"></asp:Label>
                                </ItemTemplate>
                                <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Center" />
                                <HeaderStyle CssClass="cssBorderGrv" HorizontalAlign="Left" />
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lblDelete" runat="server" CommandName="delete" Text="<img src=../../Images/Icon/cmdDelete.gif border=0 alt=Delete > "></asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Center" Width="10px" />
                                <HeaderStyle CssClass="cssBorderGrv" />
                            </asp:TemplateField>
                        </Columns>
                        <RowStyle CssClass="gvRowStyle" />
                        <AlternatingRowStyle CssClass="gvAlternatingRowStyle" />
                        <HeaderStyle CssClass="gvHeader" />
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td class="cssManage_left" colspan="2">
                </td>
            </tr>
            <tr>
                <td style="width: 158px">
                </td>
                <td style="height: 24px" align="left">
                    <input id="btnSave" type="button" value="Bảo lưu" onclick="fnInsertData()" class="cssButton" />
                    <asp:Button ID="btnCancel" runat="server" CssClass="cssButton" Text="Trở về" OnClick="btnCancel_Click"
                        Width="80px" /></td>
            </tr>
        </table>
    </div>
    <input type="hidden" runat="server" id="hidXML" />

    <script language="javascript" type="text/javascript">
                          ///////////////////////////
        
            function fnInsertData()
            {
                var txtTheLoai = document.getElementById('<%=txtTheLoai.ClientID%>');
                var ddlChuDe = document.getElementById('<%=ddlChuDe.ClientID%>');

                var hidXML = document.getElementById('<%=hidXML.ClientID%>');                
                
                if(txtTheLoai.value=="")
                {
                    alert('Nhập vào thể loại');
                    txtTheLoai.focus();
                    return;
                }
                if(ddlChuDe.value=="0")
                {
                    alert('Chọn chủ đề');
                    ddlChuDe.focus();
                    return; 
                }
                
                
                var tbl = document.getElementById('<%=grv_Catalogue.ClientID%>');
                hidXML.value="";
                var sPro="";
	            for(var i=1;i<tbl.rows.length;i++)
                {    
                      if(tbl.rows[i].cells[0].getElementsByTagName('input')[0].value!="") 
                      {  
					        sPro+= "<PrtNm>" + tbl.rows[i].cells[0].getElementsByTagName('input')[0].value+"</PrtNm>" ;
					        sPro+= "<PrtID>" + tbl.rows[i].cells[0].getElementsByTagName('span')[0].innerHTML+"</PrtID>" ;
                      }             
                }
               
                //var sValue=sPro.substr(0,sPro.lastIndexOf("^"));

                hidXML.value="<Properties>"+sPro+"</Properties>";
                
               
                var theForm=document.forms["aspnetForm"];
			   
			    hidXML.value+="<Method>SaveCatalogue_Click</Method>";
			    theForm.submit();
              
                
                
              
              

                
            }
            function tblInsertRow(obj)
            {
              // if('<%=Request.QueryString["CatID"] %>' =="" || '<%= Request.QueryString["CatID"] %>' ==null)
               // {
                    if(obj.value!="")
                    {
                      
			           var tbl = document.getElementById('<%=grv_Catalogue.ClientID%>');
		                //alert(tab.rows[1].cells[0].childNodes[0].value)
		                 for(var i=1;i<tbl.rows.length;i++)
                         {
                            if(tbl.rows[i].cells[0].getElementsByTagName('input')[0].value=="") return;
                         }
    		            
                          var lastRow = tbl.rows.length;
                          // if there's no header row in the table, then iteration = lastRow + 1
                          var iteration = lastRow;
                          var row = tbl.insertRow(lastRow);
                          row.className="gvRowStyle";                      
                          var cell = row.insertCell(0);
                          
                          if(navigator.appName == "Microsoft Internet Explorer")
                          {
                              var txt = document.createElement("<input type='text' id ='txtThuocTinh' style='width:99%' onkeyup='tblInsertRow(this)'>");
                              var img = document.createElement("<span></span>");
                              var lbl=document.createElement("<span></span>");
                          }
                          else  
                          {
                         
                              var txt = document.createElement('input');
                              txt.type = 'text';
                              txt.name = 'txtRow' + iteration;
                              //txt.id = 'txtRow' + iteration;
                              txt.id ='txtThuocTinh';
                              txt.style.width = '99%';
                              txt.onkeyup=tblInsertRow;
                              
                              var lbl=document.createElement("span");
                              
                              var img = document.createElement('span');
                              //img.src='../../Images/Icon/cmdDelete.gif';
                              
                          }                         
                         cell.appendChild(txt);
                         cell.appendChild(lbl);                    
                         cell.className="cssBorderGrv";
                         
                         //PrtID    
                         
                         cell = row.insertCell(1);
                         cell.appendChild(img);
                         cell.className="cssBorderGrv";
                         
                        var tbl=document.getElementById("tblBodyMain"); 
                        //parent.fnFullFrame(tbl.clientHeight);
            

		           }
		        //}
          }
    </script>

</asp:Content>
